<template>
    <view class="load" v-if="!load">
      <u-loading-icon
        mode="circle"
        inactive-color="#fff"
        text="正在加载..."
        vertical
      ></u-loading-icon>
    </view>
    <view v-else>
        <view class="topScreenBox">
            <view class="searchCell">
            <image src="https://golfdate.oss-cn-shenzhen.aliyuncs.com/upload/1730270429402341.png" class="searchimg">
            </image>
            <view class="scInp">
                <input type="text" v-model="searchContent" placeholder="搜索雪场" maxlength="10" placeholder-class="placname"
                @input="blurSearch" />
            </view>
            <!-- <view class="scBtnBox">
                <view class="scSumBtn" @click="subSearch">搜索</view>
            </view> -->
            </view>
        </view>
        <view class="listbox" v-for="(item,index) in skiList" :key="index">
            <view class="contnet" @click="nav_to('/pages/album/ski_details?id='+item.ID)">
                <image class="skiimg" :src="item.ShopLogo" mode="aspectFill"></image>
                <view class="skicon">
                    <view class="skiname">{{item.ShopName}}</view>
                    <view class="skinum">{{'打卡记录：'+item.MyTakeNum}}</view>
                </view>
                <view class="distext">
                  {{item.Distance?item.Distance.toFixed(2)+'km':'0km'}}
                </view>
            </view>
        </view>
        <view style="height:100rpx;"></view>
    </view>
</template>

<script>
export default {
components: {},
data() {
return {
  load:false,
  skiList:[],
  PageIndex:1,
  PageSize:10,
  searchContent:'',
  longitude:'',
  latitude:'',
};
},
onLoad(){
  this.getCity()
  // this.getskiList()
},
  // // 触底事件
  onReachBottom() {
    this.PageIndex++
    this.getskiList()
  },
methods: {
  blurSearch(){
    this.getskiList()
  },
  //雪场列表
    async getskiList(){
      let res = await this.$api.post('Shops/List',{
        City:'',
        ShopName:this.searchContent,
        PageIndex:this.PageIndex,
        PageSize:this.PageSize,
        Latitude:this.latitude,
        Longitude:this.longitude,
      })
      if(res.code == 0){
        if(this.PageIndex == 1){
          this.skiList = res.data
        }else{
          this.skiList = this.skiList.concat(res.data)
        }
        this.load = true
      }
    },
    // 获取定位
    getLocationSysc() {
      let _this = this;
      return new Promise((resolve, reject) => {
        uni.getLocation({
          type: "gcj02",
          success: function (res) {
            resolve(res);
          },
          fail: function (err) {
            const defaultLocation = {
              latitude: 0,
              longitude: 0,
            };
            resolve(defaultLocation);
          },
        });
      });
    },
    async getCity() {
      try {
        let loc = await this.getLocationSysc();
        this.longitude = loc.longitude;
        this.latitude = loc.latitude;
      } catch (err) {
        this.longitude = err.longitude;
        this.latitude = err.latitude;
      }
      this.getskiList()
    },
},
}
</script>
<style lang='scss'>
page{
    background-color: #f6f6f6;
}
.topScreenBox {
    width: 100%;
    padding: 16rpx 32rpx;
    box-sizing: border-box;
    background-color: #fff;
  .searchCell {
    width: 100%;
    height: 72rpx;
    display: flex;
    align-items: center;
    // border: 2rpx solid #e4e4e4;
    background-color: #F6F6F6;
    border-radius: 36rpx;

    .scIcon {
      margin-right: 16rpx;
    }

    .searchimg {
      width: 32rpx;
      height: 32rpx;
      margin-left: 24rpx;
    }

    .scInp {
      flex: 1;
      margin-left: 5rpx;

      >input {
        width: 100%;
        background: transparent;
      }

      .placname {
        color: #999999;
        font-size: 24rpx;
      }
    }

    .scBtnBox {
      display: flex;
      // margin-left: auto;
      margin-right: 8rpx;

      .scSumBtn {
        padding: 13rpx 34rpx;
        background: #706eee;
        border-radius: 32rpx;
        font-weight: 500;
        font-size: 24rpx;
        color: #ffffff;
        display: flex;
        justify-content: center;
        align-items: center;
        position: relative;

        &:last-child {
          margin-left: 20rpx;
        }
      }
    }
  }

  .tagBox {
    width: 100%;
    // overflow-y: auto;
    margin-top: 20rpx;
    padding-bottom: 20rpx;

    .tagList {
      display: flex;
      align-items: center;
      flex-wrap: wrap;
      width: 100%;

      .tagCell {
        padding: 10rpx 20rpx;
        border-radius: 12rpx;
        border: 2rpx solid #e4e4e4;
        background: white;
        color: #706eee;
        margin: 0 20rpx 10rpx;
        margin-left: 0;
        white-space: nowrap;
        font-size: 22rpx;
      }

      .tagIng {
        border: 2rpx solid #e4e4e4;
        background: #e4e4e4;
        color: white;
      }
    }
  }
}
.listbox{
    margin: 0 auto;
    margin-top: 24rpx;
    width: 702rpx;
    
    .contnet{
        width: 702rpx;
        height: 176rpx;
        background: #FFFFFF;
        border-radius: 16rpx;
        margin-bottom: 24rpx;
        padding: 24rpx;
        box-sizing: border-box;
        display: flex;
        align-items: center;
     .skiimg{
        width: 128rpx;
        height: 128rpx;
        // background: #F0F0F0;
        border-radius: 16rpx;
        margin-right: 24rpx;
     }   
     .skicon{
        width: 350rpx;
        .skiname{
            font-size: 32rpx;
            font-weight: bold;
            color: #333333;
            margin-bottom: 16rpx;
        }
        .skinum{
            font-size: 28rpx;
            color: #999999;
        }
     }
     .distext{
      font-size: 28rpx;
      margin-left: auto;
     }
    }
}
</style>